package org.example.service.impl;

import org.example.interceptor.LoginInterceptor;
import org.example.manager.DomainManager;
import org.example.model.DomainDO;
import org.example.mapper.DomainMapper;
import org.example.service.DomainService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.util.CommonUtil;
import org.example.vo.DomainVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 谢超
 * @since 2023-08-21
 */
@Service
public class DomainServiceImpl implements DomainService {

    @Resource
    private DomainManager domainManager;

    @Override
    public List<DomainVO> getDomainAllList() {
        // 获取用户账号
        long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        List<DomainDO> customDomainList = domainManager.listCustomDomain(accountNo);
        List<DomainDO> officalDomainList = domainManager.listOfficalDomain();
        officalDomainList.addAll(customDomainList);
        return officalDomainList.stream().map(item -> CommonUtil.beanClone(item, new DomainVO())).collect(Collectors.toList());
    }
}
